﻿using APP.HELPER.Data.Helper;
using APP.HELPER.Utils;
using APP.HELPER.Utils.System;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.DXErrorProvider;
using DevExpress.XtraWizard;
using Service.Properties;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;

namespace Service
{
    public class XfmService : XtraForm
    {
        private delegate void ProcessEventHander(object sender, int percent);
        public delegate void SuccessEventHander(object sender, Customer customer);
        private IContainer components = null;
        private WizardControl wcService;
        private WelcomeWizardPage wpinfo;
        private DevExpress.XtraWizard.WizardPage wpactive;
        private CompletionWizardPage wpcompletion;
        private TextEdit txtActiveCode;
        private LabelControl lblActiveCode;
        private TextEdit txtRegisterCode;
        private LabelControl lblRegisterCode;
        private TextEdit txtComputerCode;
        private LabelControl lblComputerCode;
        private PictureEdit pic1;
        private MarqueeProgressBarControl Bar1;
        private ImageCollection imageCollection1;
        private LabelControl labelControl1;
        private LabelControl labelControl2;
        private MarqueeProgressBarControl Bar2;
        private PictureEdit pic2;
        private LabelControl labelControl3;
        private MarqueeProgressBarControl Bar3;
        private PictureEdit pic3;
        private LabelControl lblTitle;
        private LabelControl lblMessage;
        private PictureEdit pic0;
        private DXErrorProvider Err;
        private event XfmService.ProcessEventHander Process;
        public event XfmService.SuccessEventHander Success;
        public sealed override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = value;
            }
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing && this.components != null)
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }
        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(XfmService));
            this.wcService = new WizardControl();
            this.pic0 = new PictureEdit();
            this.lblMessage = new LabelControl();
            this.lblTitle = new LabelControl();
            this.wpinfo = new WelcomeWizardPage();
            this.txtActiveCode = new TextEdit();
            this.lblActiveCode = new LabelControl();
            this.txtRegisterCode = new TextEdit();
            this.lblRegisterCode = new LabelControl();
            this.txtComputerCode = new TextEdit();
            this.lblComputerCode = new LabelControl();
            this.wpactive = new DevExpress.XtraWizard.WizardPage();
            this.labelControl3 = new LabelControl();
            this.Bar3 = new MarqueeProgressBarControl();
            this.pic3 = new PictureEdit();
            this.labelControl2 = new LabelControl();
            this.Bar2 = new MarqueeProgressBarControl();
            this.pic2 = new PictureEdit();
            this.labelControl1 = new LabelControl();
            this.Bar1 = new MarqueeProgressBarControl();
            this.pic1 = new PictureEdit();
            this.wpcompletion = new CompletionWizardPage();
            this.imageCollection1 = new ImageCollection(this.components);
            this.Err = new DXErrorProvider(this.components);
            ((ISupportInitialize)this.wcService).BeginInit();
            this.wcService.SuspendLayout();
            ((ISupportInitialize)this.pic0.Properties).BeginInit();
            this.wpinfo.SuspendLayout();
            ((ISupportInitialize)this.txtActiveCode.Properties).BeginInit();
            ((ISupportInitialize)this.txtRegisterCode.Properties).BeginInit();
            ((ISupportInitialize)this.txtComputerCode.Properties).BeginInit();
            this.wpactive.SuspendLayout();
            ((ISupportInitialize)this.Bar3.Properties).BeginInit();
            ((ISupportInitialize)this.pic3.Properties).BeginInit();
            ((ISupportInitialize)this.Bar2.Properties).BeginInit();
            ((ISupportInitialize)this.pic2.Properties).BeginInit();
            ((ISupportInitialize)this.Bar1.Properties).BeginInit();
            ((ISupportInitialize)this.pic1.Properties).BeginInit();
            ((ISupportInitialize)this.imageCollection1).BeginInit();
            ((ISupportInitialize)this.Err).BeginInit();
            base.SuspendLayout();
            this.wcService.AnimationInterval = 100;
            this.wcService.CancelText = "&Huỷ";
            this.wcService.Controls.Add(this.pic0);
            this.wcService.Controls.Add(this.lblMessage);
            this.wcService.Controls.Add(this.lblTitle);
            this.wcService.Controls.Add(this.wpinfo);
            this.wcService.Controls.Add(this.wpactive);
            this.wcService.Controls.Add(this.wpcompletion);
            this.wcService.FinishText = "Kết Thúc";
            this.wcService.HelpText = "&Trợ giúp";
            this.wcService.HelpVisible = true;
            this.wcService.ImeMode = ImeMode.NoControl;
            this.wcService.Name = "wcService";
            this.wcService.NextText = "&Tiếp Theo >";
            this.wcService.Pages.AddRange(new BaseWizardPage[]
			{
				this.wpinfo,
				this.wpactive,
				this.wpcompletion
			});
            this.wcService.PreviousText = "< &Trở Lại";
            this.wcService.Text = "";
            this.wcService.WizardStyle = WizardStyle.WizardAero;
            this.wcService.PrevClick += new WizardCommandButtonClickEventHandler(this.WcServicePrevClick);
            this.wcService.SelectedPageChanged += new WizardPageChangedEventHandler(this.WcServiceSelectedPageChanged);
            this.wcService.NextClick += new WizardCommandButtonClickEventHandler(this.WcServiceNextClick);
            this.pic0.Location = new Point(3, 42);
            this.pic0.Name = "pic0";
            this.pic0.Properties.BorderStyle = BorderStyles.NoBorder;
            this.pic0.Size = new Size(32, 27);
            this.pic0.TabIndex = 14;
            this.pic0.Visible = false;
            this.lblMessage.Location = new Point(41, 50);
            this.lblMessage.Name = "lblMessage";
            this.lblMessage.Size = new Size(243, 13);
            this.lblMessage.TabIndex = 10;
            this.lblMessage.Text = "Vui lòng nhập mã đăng ký và mã kích hoạt (nếu có)";
            this.lblTitle.Location = new Point(41, 12);
            this.lblTitle.Name = "lblTitle";
            this.lblTitle.Size = new Size(160, 13);
            this.lblTitle.TabIndex = 9;
            this.lblTitle.Text = "Kích hoạt Phần Mềm Quản Lý Kho";
            this.wpinfo.Controls.Add(this.txtActiveCode);
            this.wpinfo.Controls.Add(this.lblActiveCode);
            this.wpinfo.Controls.Add(this.txtRegisterCode);
            this.wpinfo.Controls.Add(this.lblRegisterCode);
            this.wpinfo.Controls.Add(this.txtComputerCode);
            this.wpinfo.Controls.Add(this.lblComputerCode);
            this.wpinfo.Name = "wpinfo";
            this.wpinfo.Size = new Size(378, 112);
            this.wpinfo.Text = "";
            this.txtActiveCode.Location = new Point(76, 64);
            this.txtActiveCode.Name = "txtActiveCode";
            this.txtActiveCode.Size = new Size(296, 20);
            this.txtActiveCode.TabIndex = 38;
            this.txtActiveCode.EditValueChanging += new ChangingEventHandler(this.TxtActiveCodeEditValueChanging);
            this.lblActiveCode.Location = new Point(2, 67);
            this.lblActiveCode.Name = "lblActiveCode";
            this.lblActiveCode.Size = new Size(62, 13);
            this.lblActiveCode.TabIndex = 36;
            this.lblActiveCode.Text = "Mã Kích Hoạt";
            this.txtRegisterCode.Location = new Point(76, 33);
            this.txtRegisterCode.Name = "txtRegisterCode";
            this.txtRegisterCode.Size = new Size(296, 20);
            this.txtRegisterCode.TabIndex = 40;
            this.txtRegisterCode.EditValueChanging += new ChangingEventHandler(this.TxtRegisterCodeEditValueChanging);
            this.lblRegisterCode.Location = new Point(2, 36);
            this.lblRegisterCode.Name = "lblRegisterCode";
            this.lblRegisterCode.Size = new Size(58, 13);
            this.lblRegisterCode.TabIndex = 35;
            this.lblRegisterCode.Text = "Mã Đăng Ký";
            this.txtComputerCode.Location = new Point(77, 3);
            this.txtComputerCode.Name = "txtComputerCode";
            this.txtComputerCode.Properties.ReadOnly = true;
            this.txtComputerCode.Size = new Size(296, 20);
            this.txtComputerCode.TabIndex = 39;
            this.lblComputerCode.Location = new Point(2, 6);
            this.lblComputerCode.Name = "lblComputerCode";
            this.lblComputerCode.Size = new Size(37, 13);
            this.lblComputerCode.TabIndex = 37;
            this.lblComputerCode.Text = "Mã Máy";
            this.wpactive.Controls.Add(this.labelControl3);
            this.wpactive.Controls.Add(this.Bar3);
            this.wpactive.Controls.Add(this.pic3);
            this.wpactive.Controls.Add(this.labelControl2);
            this.wpactive.Controls.Add(this.Bar2);
            this.wpactive.Controls.Add(this.pic2);
            this.wpactive.Controls.Add(this.labelControl1);
            this.wpactive.Controls.Add(this.Bar1);
            this.wpactive.Controls.Add(this.pic1);
            this.wpactive.Name = "wpactive";
            this.wpactive.Size = new Size(378, 112);
            this.wpactive.Text = "";
            this.labelControl3.Location = new Point(35, 81);
            this.labelControl3.Name = "labelControl3";
            this.labelControl3.Size = new Size(137, 13);
            this.labelControl3.TabIndex = 8;
            this.labelControl3.Text = "Thực hiện đăng ký sản phẩm";
            this.Bar3.EditValue = 0;
            this.Bar3.Location = new Point(179, 83);
            this.Bar3.Name = "Bar3";
            this.Bar3.Properties.UseParentBackground = true;
            this.Bar3.Size = new Size(193, 13);
            this.Bar3.TabIndex = 7;
            this.Bar3.Visible = false;
            this.pic3.EditValue = componentResourceManager.GetObject("pic3.EditValue");
            this.pic3.Location = new Point(1, 74);
            this.pic3.Name = "pic3";
            this.pic3.Properties.Appearance.BackColor = Color.Transparent;
            this.pic3.Properties.Appearance.Options.UseBackColor = true;
            this.pic3.Properties.BorderStyle = BorderStyles.NoBorder;
            this.pic3.Size = new Size(32, 28);
            this.pic3.TabIndex = 6;
            this.pic3.Visible = false;
            this.labelControl2.Location = new Point(35, 46);
            this.labelControl2.Name = "labelControl2";
            this.labelControl2.Size = new Size(97, 13);
            this.labelControl2.TabIndex = 5;
            this.labelControl2.Text = "Kiểm tra mã đăng ký";
            this.Bar2.EditValue = 0;
            this.Bar2.Location = new Point(179, 48);
            this.Bar2.Name = "Bar2";
            this.Bar2.Properties.UseParentBackground = true;
            this.Bar2.Size = new Size(193, 13);
            this.Bar2.TabIndex = 4;
            this.Bar2.Visible = false;
            this.pic2.EditValue = componentResourceManager.GetObject("pic2.EditValue");
            this.pic2.Location = new Point(1, 39);
            this.pic2.Name = "pic2";
            this.pic2.Properties.Appearance.BackColor = Color.Transparent;
            this.pic2.Properties.Appearance.Options.UseBackColor = true;
            this.pic2.Properties.BorderStyle = BorderStyles.NoBorder;
            this.pic2.Size = new Size(32, 28);
            this.pic2.TabIndex = 3;
            this.pic2.Visible = false;
            this.labelControl1.Location = new Point(36, 10);
            this.labelControl1.Name = "labelControl1";
            this.labelControl1.Size = new Size(76, 13);
            this.labelControl1.TabIndex = 2;
            this.labelControl1.Text = "Kết nối máy chủ";
            this.Bar1.EditValue = 0;
            this.Bar1.Location = new Point(180, 12);
            this.Bar1.Name = "Bar1";
            this.Bar1.Properties.UseParentBackground = true;
            this.Bar1.Size = new Size(193, 13);
            this.Bar1.TabIndex = 1;
            this.pic1.EditValue = componentResourceManager.GetObject("pic1.EditValue");
            this.pic1.Location = new Point(2, 3);
            this.pic1.Name = "pic1";
            this.pic1.Properties.Appearance.BackColor = Color.Transparent;
            this.pic1.Properties.Appearance.Options.UseBackColor = true;
            this.pic1.Properties.BorderStyle = BorderStyles.NoBorder;
            this.pic1.Size = new Size(32, 28);
            this.pic1.TabIndex = 0;
            this.pic1.Visible = false;
            this.wpcompletion.Name = "wpcompletion";
            this.wpcompletion.Size = new Size(378, 112);
            this.wpcompletion.Text = "";
            this.imageCollection1.ImageStream = (ImageCollectionStreamer)componentResourceManager.GetObject("imageCollection1.ImageStream");
            this.Err.ContainerControl = this;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(438, 272);
            base.Controls.Add(this.wcService);
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "XfmService";
            base.ShowIcon = false;
            base.ShowInTaskbar = false;
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "Phần Mềm Quản Lý Kho";
            ((ISupportInitialize)this.wcService).EndInit();
            this.wcService.ResumeLayout(false);
            this.wcService.PerformLayout();
            ((ISupportInitialize)this.pic0.Properties).EndInit();
            this.wpinfo.ResumeLayout(false);
            this.wpinfo.PerformLayout();
            ((ISupportInitialize)this.txtActiveCode.Properties).EndInit();
            ((ISupportInitialize)this.txtRegisterCode.Properties).EndInit();
            ((ISupportInitialize)this.txtComputerCode.Properties).EndInit();
            this.wpactive.ResumeLayout(false);
            this.wpactive.PerformLayout();
            ((ISupportInitialize)this.Bar3.Properties).EndInit();
            ((ISupportInitialize)this.pic3.Properties).EndInit();
            ((ISupportInitialize)this.Bar2.Properties).EndInit();
            ((ISupportInitialize)this.pic2.Properties).EndInit();
            ((ISupportInitialize)this.Bar1.Properties).EndInit();
            ((ISupportInitialize)this.pic1.Properties).EndInit();
            ((ISupportInitialize)this.imageCollection1).EndInit();
            ((ISupportInitialize)this.Err).EndInit();
            base.ResumeLayout(false);
        }
        private void RaiseProcessEventHander(int percent)
        {
            if (this.Process != null)
            {
                this.Process(this, percent);
            }
        }
        private void RaiseSuccessEventHander(Customer customer)
        {
            if (this.Success != null)
            {
                this.Success(this, customer);
            }
        }
        public XfmService()
        {
            this.InitializeComponent();
            this.Text = APP.HELPER.Utils.AssemblyHelper.AssemblyTitle;
            this.lblTitle.Text = "Kích hoạt " + this.Text;
            SystemInfoHelper.SetDefault();
            this.txtComputerCode.Text = MyRegister.GenId();
            Assembly.GetAssembly(base.GetType());
            this.Process += new XfmService.ProcessEventHander(this.XfmServiceProcess);
        }
        private void TxtActiveCodeEditValueChanging(object sender, ChangingEventArgs e)
        {
            CODE cODE = new CODE
            {
                Active = this.txtActiveCode.Text,
                Code = this.txtRegisterCode.Text
            };
            CODE.ComputerCode = this.txtComputerCode.Text;
            if (!cODE.ActiveLicense() & !string.IsNullOrEmpty(this.txtActiveCode.Text))
            {
                this.Err.SetError(this.txtActiveCode, "Mã kích hoạt không đúng.");
                this.Err.SetIconAlignment(this.txtActiveCode, ErrorIconAlignment.MiddleRight);
            }
            else
            {
                this.txtActiveCode.ErrorText = "";
                this.Err.SetError(this.txtActiveCode, null);
            }
        }
        private void TxtRegisterCodeEditValueChanging(object sender, ChangingEventArgs e)
        {
            CODE cODE = new CODE();
            this.wpinfo.AllowNext = false;
            if (!cODE.CodeMacth(this.txtRegisterCode.Text))
            {
                this.Err.SetError(this.txtRegisterCode, "Mã đăng ký không đúng cấu trúc.");
                this.Err.SetIconAlignment(this.txtRegisterCode, ErrorIconAlignment.MiddleRight);
            }
            else
            {
                this.wpinfo.AllowNext = true;
                this.txtRegisterCode.ErrorText = "";
                this.Err.SetError(this.txtRegisterCode, null);
            }
        }
        private void WcServiceNextClick(object sender, WizardCommandButtonClickEventArgs e)
        {
        }
        private void WcServicePrevClick(object sender, WizardCommandButtonClickEventArgs e)
        {
            if (e.Page == this.wpcompletion)
            {
                this.wcService.SelectedPage = this.wpinfo;
                this.pic0.Visible = false;
            }
        }
        private void WcServiceSelectedPageChanged(object sender, WizardPageChangedEventArgs e)
        {
            if (e.Page == this.wpactive)
            {
                this.Bar1.Visible = false;
                this.Bar2.Visible = false;
                this.Bar3.Visible = false;
                this.pic1.Visible = false;
                this.pic2.Visible = false;
                this.pic3.Visible = false;
                this.wpactive.AllowBack = false;
                this.wpactive.AllowNext = false;
                if (!string.IsNullOrEmpty(this.txtRegisterCode.ErrorText) | !string.IsNullOrEmpty(this.txtActiveCode.ErrorText))
                {
                    this.wcService.SelectedPage = this.wpinfo;
                }
                else
                {
                    this.lblMessage.Text = "Đang thực hiện quá trình kích hoạt.";
                    Thread thread = new Thread(new ThreadStart(this.Execute));
                    thread.Start();
                }
            }
            else
            {
                if (e.Page == this.wpinfo)
                {
                    this.lblMessage.Text = "Vui lòng nhập mã đăng ký và mã kích hoạt (nếu có).";
                }
            }
        }
        private void XfmServiceProcess(object sender, int percent)
        {
            if (this.wcService.InvokeRequired)
            {
                XfmService.ProcessEventHander method = new XfmService.ProcessEventHander(this.XfmServiceProcess);
                base.Invoke(method, new object[]
				{
					sender,
					percent
				});
            }
            else
            {
                switch (percent)
                {
                    case 1:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Đăng ký thất bại.";
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 2:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Kiểm tra thông tin mã đăng ký thất bại.";
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 3:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Đăng ký thàng công.";
                        this.wpcompletion.AllowBack = false;
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.OK16;
                        this.pic3.Image = Resources.OK16;
                        this.Bar3.Visible = false;
                        break;

                    case 4:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Không thể kết nối với máy chủ.";
                        this.pic1.Visible = true;
                        this.pic1.Image = Resources.Cancel16;
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 5:
                        this.pic1.Visible = true;
                        this.pic1.Image = Resources.OK16;
                        break;

                    case 6:
                        this.Bar1.Visible = false;
                        this.Bar2.Visible = true;
                        break;

                    case 7:
                        this.Bar2.Visible = false;
                        this.Bar3.Visible = true;
                        break;

                    case 8:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Không thể lấy thông tin khách hàng.";
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 9:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Đăng ký thất bại.";
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 10:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Kiểm tra thông tin mã đăng ký thất bại.";
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 11:
                        this.pic2.Visible = true;
                        this.pic2.Image = Resources.OK16;
                        break;

                    case 12:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.wpcompletion.AllowBack = false;
                        this.lblMessage.Text = "Đăng ký thàng công.";
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.OK16;
                        this.pic3.Image = Resources.OK16;
                        this.Bar3.Visible = false;
                        break;

                    case 13:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Đăng ký thất bại.";
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 14:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Mã đăng ký bất hợp pháp.";
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 15:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Mã đăng ký đã sử dụng hết.";
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 16:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Mã đăng ký đã hết hạn.";
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 17:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Mã đăng ký không hợp lệ.";
                        this.pic2.Image = Resources.Cancel16;
                        this.pic2.Visible = true;
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 18:
                        this.Bar2.Visible = false;
                        this.Bar3.Visible = true;
                        break;

                    case 19:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Không thể lấy thông tin khách hàng.";
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 20:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Đăng ký thất bại.";
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 21:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Kiểm tra thông tin mã đăng ký thất bại.";
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 22:
                        this.pic2.Visible = true;
                        this.pic2.Image = Resources.OK16;
                        break;

                    case 23:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Đăng ký thàng công.";
                        this.wpcompletion.AllowBack = false;
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.OK16;
                        this.pic3.Image = Resources.OK16;
                        this.Bar3.Visible = false;
                        break;

                    case 24:
                        this.wcService.SelectedPage = this.wpcompletion;
                        this.lblMessage.Text = "Đăng ký thất bại.";
                        this.pic0.Visible = true;
                        this.pic0.Image = Resources.Cancel16;
                        break;

                    case 25:
                        this.Bar3.Visible = false;
                        break;
                }
            }
        }
        private void Execute()
        {
            if (!string.IsNullOrEmpty(this.txtActiveCode.Text))
            {
                CODE cODE = new CODE
                {
                    Active = this.txtActiveCode.Text,
                    Code = this.txtRegisterCode.Text,
                    Command = 1
                };
                CODE.CompanyName = "Công Ty Phần Mềm Hoàn Hảo.";
                CODE.ComputerCode = this.txtComputerCode.Text;
                CODE.Contact = "Trần Hoàng Tâm.";
                cODE.Created = DateTime.Now;
                cODE.Day = -1;
                cODE.Language = "VN";
                cODE.License = 1;
                cODE.Limit = DateTime.Now;
                cODE.Mobile = "";
                cODE.Number = 1;
                cODE.SoftId = SystemInfoHelper.GetSoftware(APP.HELPER.Utils.AssemblyHelper.AssemblyTitle);
                cODE.SoftName = APP.HELPER.Utils.AssemblyHelper.AssemblyTitle;
                cODE.Tel = "";
                cODE.Today = DateTime.Now;
                cODE.Type = 1;
                cODE.Version = APP.HELPER.Utils.AssemblyHelper.AssemblyVersion;
                if (!cODE.WriteFile("Perfect.Lic"))
                {
                    this.RaiseProcessEventHander(1);
                }
                else
                {
                    if (!cODE.ReadFile("Perfect.Lic", this.txtComputerCode.Text))
                    {
                        this.RaiseProcessEventHander(2);
                    }
                    else
                    {
                        this.RaiseProcessEventHander(3);
                    }
                }
            }
            else
            {
                if (!Internet.IsConnectedToInternet())
                {
                    this.RaiseProcessEventHander(4);
                }
                else
                {
                    SqlHelper sqlHelper = new SqlHelper("HPqrGX/piQz0Xe4u/h/67gQ3uyF/l8Jnvceflfn0g5a097J0Dujgoj8bqG7F7buoYB2Mt+NKyXJ77rNdpJJ69tNga+CVb/KOMzARhvb5JWkXymCWnUJWzzgLCgblpEMy", "07071983", true);
                    if (sqlHelper.Open() == "OK")
                    {
                        this.RaiseProcessEventHander(5);
                        sqlHelper.Close();
                        this.RaiseProcessEventHander(6);
                        Keycode keycode = new Keycode();
                        License license = new License();
                        if (license.Get(this.txtRegisterCode.Text, this.txtComputerCode.Text) == "OK")
                        {
                            if (!(keycode.Get(this.txtRegisterCode.Text) == "OK"))
                            {
                                this.RaiseProcessEventHander(17);
                                return;
                            }
                            if (keycode.Blacklist)
                            {
                                this.RaiseProcessEventHander(14);
                                return;
                            }
                            this.RaiseProcessEventHander(7);
                            Customer customer = new Customer();
                            if (customer.Get(keycode.Id_Contact) != "OK")
                            {
                                this.RaiseProcessEventHander(8);
                                return;
                            }
                            CODE cODE = new CODE
                            {
                                Active = this.txtActiveCode.Text,
                                Code = this.txtRegisterCode.Text,
                                Command = 1
                            };
                            CODE.CompanyName = customer.NameCompany;
                            CODE.Address = customer.Address;
                            CODE.ComputerCode = this.txtComputerCode.Text;
                            CODE.Contact = customer.ContactMan;
                            cODE.Created = DateTime.Now;
                            cODE.Day = -1;
                            cODE.Email = customer.Email;
                            cODE.Fax = customer.Fax;
                            CODE.Website = customer.Website;
                            cODE.Language = "VN";
                            cODE.License = keycode.TypeActive;
                            cODE.Limit = keycode.DateLimit;
                            cODE.Mobile = customer.Mobile;
                            cODE.Number = keycode.NumActive;
                            cODE.SoftId = SystemInfoHelper.GetSoftware(APP.HELPER.Utils.AssemblyHelper.AssemblyTitle);
                            cODE.SoftName = APP.HELPER.Utils.AssemblyHelper.AssemblyTitle;
                            cODE.Tel = customer.Tell;
                            cODE.Today = DateTime.Now;
                            cODE.Type = keycode.TypeSoft;
                            cODE.Version = APP.HELPER.Utils.AssemblyHelper.AssemblyVersion;
                            if (!(license.Update(this.txtRegisterCode.Text, this.txtComputerCode.Text) == "OK"))
                            {
                                this.RaiseProcessEventHander(13);
                                return;
                            }
                            this.RaiseProcessEventHander(12);
                            this.RaiseSuccessEventHander(customer);
                            if (!cODE.WriteFile("Perfect.Lic"))
                            {
                                this.RaiseProcessEventHander(9);
                                return;
                            }
                            if (!cODE.ReadFile("Perfect.Lic", this.txtComputerCode.Text))
                            {
                                this.RaiseProcessEventHander(10);
                                return;
                            }
                            this.RaiseProcessEventHander(11);
                        }
                        else
                        {
                            if (!(keycode.Get(this.txtRegisterCode.Text) == "OK"))
                            {
                                this.RaiseProcessEventHander(17);
                                return;
                            }
                            if (keycode.Blacklist)
                            {
                                this.RaiseProcessEventHander(14);
                                return;
                            }
                            if (keycode.TypeActive == 1 | keycode.TypeActive > 3)
                            {
                                if (keycode.NumActive == 0)
                                {
                                    this.RaiseProcessEventHander(15);
                                    return;
                                }
                            }
                            if (keycode.DateLimit.CompareTo(DateTime.Now) < 0)
                            {
                                this.RaiseProcessEventHander(16);
                                return;
                            }
                            this.RaiseProcessEventHander(18);
                            Customer customer = new Customer();
                            if (customer.Get(keycode.Id_Contact) != "OK")
                            {
                                this.RaiseProcessEventHander(19);
                                return;
                            }
                            CODE cODE = new CODE
                            {
                                Active = this.txtActiveCode.Text,
                                Code = this.txtRegisterCode.Text,
                                Command = 1
                            };
                            CODE.CompanyName = customer.NameCompany;
                            CODE.Address = customer.Address;
                            CODE.ComputerCode = this.txtComputerCode.Text;
                            CODE.Contact = customer.ContactMan;
                            CODE.Website = customer.Website;
                            cODE.Created = DateTime.Now;
                            cODE.Day = -1;
                            cODE.Email = customer.Email;
                            cODE.Fax = customer.Fax;
                            cODE.Language = "VN";
                            cODE.License = keycode.TypeActive;
                            cODE.Limit = keycode.DateLimit;
                            cODE.Mobile = customer.Mobile;
                            cODE.Number = keycode.NumActive;
                            cODE.SoftId = SystemInfoHelper.GetSoftware(APP.HELPER.Utils.AssemblyHelper.AssemblyTitle);
                            cODE.SoftName = APP.HELPER.Utils.AssemblyHelper.AssemblyTitle;
                            cODE.Tel = customer.Tell;
                            cODE.Today = DateTime.Now;
                            cODE.Type = keycode.TypeSoft;
                            cODE.Version = APP.HELPER.Utils.AssemblyHelper.AssemblyVersion;
                            if (!(license.Insert(APP.HELPER.Utils.AssemblyHelper.AssemblyTitle, this.txtRegisterCode.Text, this.txtComputerCode.Text, true, APP.HELPER.Utils.AssemblyHelper.AssemblyVersion) == "OK"))
                            {
                                this.RaiseProcessEventHander(24);
                                return;
                            }
                            this.RaiseProcessEventHander(23);
                            this.RaiseSuccessEventHander(customer);
                            if (!cODE.WriteFile("Perfect.Lic"))
                            {
                                this.RaiseProcessEventHander(20);
                                return;
                            }
                            if (!cODE.ReadFile("Perfect.Lic", this.txtComputerCode.Text))
                            {
                                this.RaiseProcessEventHander(21);
                                return;
                            }
                            this.RaiseProcessEventHander(22);
                        }
                        this.RaiseProcessEventHander(25);
                    }
                    else
                    {
                        this.RaiseProcessEventHander(4);
                    }
                }
            }
        }
    }
}